cmake_minimum_required(VERSION 3.15)
project(visual_sort CXX)

message(STATUS "Compiler: ${CMAKE_CXX_COMPILER_ID}")
message(STATUS "Platform: ${CMAKE_CXX_PLATFORM_ID}")

set(CMAKE_CXX_STANDARD 20)


# To configure whether enable boost::sort library support
find_package(Boost)
message(STATUS "Boost_FOUND: ${Boost_FOUND}")
set(VISUAL_SORT_ENABLE_BOOST_SORT_SUPPORT ${Boost_FOUND})
message(STATUS "VISUAL_SORT_ENABLE_BOOST_SORT_SUPPORT: ${VISUAL_SORT_ENABLE_BOOST_SORT_SUPPORT}")


# To configure whether enable gfx::timsort library support
if (EXISTS "${PROJECT_SOURCE_DIR}/cpp-TimSort/include/gfx/timsort.hpp")
    set(GFX_TIMSORT_FOUND TRUE)
else ()
    set(GFX_TIMSORT_FOUND FALSE)
endif ()
message(STATUS "GFX_TIMSORT_FOUND: ${GFX_TIMSORT_FOUND}")
set(VISUAL_SORT_ENABLE_GFX_TIMSORT_SUPPORT ${GFX_TIMSORT_FOUND})
message(STATUS "VISUAL_SORT_ENABLE_GFX_TIMSORT_SUPPORT: ${VISUAL_SORT_ENABLE_GFX_TIMSORT_SUPPORT}")

if (VISUAL_SORT_ENABLE_GFX_TIMSORT_SUPPORT)
    include_directories(./cpp-TimSort/include)
endif ()


if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
    add_compile_options(-Wall -Wextra)
elseif (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
    add_compile_options(/Zc:__cplusplus)
    add_compile_options(/openmp)
    if (${CMAKE_BUILD_TYPE} MATCHES "Debug")
        add_compile_options(/MTd)
    else ()
        add_compile_options(/O2)
        add_compile_options(/MT)
    endif ()
endif ()


if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
    add_compile_options(-fuse-ld=lld)
endif ()


include_directories(~/git/Kerbal/include)


add_subdirectory(./include)
add_subdirectory(./src)


if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
    set(LINK_LIBS nana Xcursor pthread omp)
    foreach (lib ${LINK_LIBS})
        message(STATUS "Finding ${lib}")
        find_library(LIB_${lib} ${lib} REQUIRED)
        message(STATUS "LIB_${lib}: ${LIB_${lib}}")
        target_link_libraries(visual_sort ${LIB_${lib}})
    endforeach ()
elseif (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
    include_directories(C:/Users/Peter/include)
    include_directories(C:/Users/Peter/git/Kerbal/include)
    link_directories(C:/Users/Peter/lib_vs)
    if (${CMAKE_BUILD_TYPE} MATCHES "Debug")
        target_link_libraries(visual_sort C:/Users/Peter/lib_vs/nana_v142_Debug_x64.lib)
    else ()
        target_link_libraries(visual_sort C:/Users/Peter/lib_vs/nana_v142_Release_x64.lib)
    endif ()
endif ()